<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function deepCopy(obj1) {
        var obj2 = Array.isArray(obj1) ? [] : {}
        if (obj1 && typeof obj1 === 'object') {
          for (var i in obj1) {
            var prop = obj1[i] // 避免相互引用造成死循环，如obj1.a=obj
            if (prop == obj1) {
              continue
            }
            if (obj1.hasOwnProperty(i)) {
              if (prop && typeof prop === 'object') {
                // 如果子属性为引用数据类型，递归复制
                obj2[i] = deepCopy(prop)
              } else {
                // 如果是基本数据类型，只是简单的复制
                obj2[i] = prop
              }
            }
          }
        }
        return obj2
      }

      var obj1 = {
        a:1,
        c: {
          d: 3,
        },
      }
      var obj2 = deepCopy(obj1)
      obj1.c.d = 4
      console.log('🚀🚀🚀wimi======>>>obj2', obj2)
    </script>
  </body>
</html>
